package modelLag;
import java.util.ArrayList;

/**
 * Description of the class CustomerCon.
 * 
 * @author (Christian, Umut, Christoffer, Patrick, Simon) 
 * @project (Semesterprojekt)
 * @version (2014.12.09)
 */
public class CustomerCon
{
    private static CustomerCon instance = null;
    private ArrayList<Customer> customers;

    /**
     * Constructor for objects of class CustomerCon
     */
    private CustomerCon(){
        customers = new ArrayList<Customer>();
        
        // test
        CustomerType CuType1 = new CustomerType("Privatkunde", 10);
        Customer customer1 = new Customer("Kristian James", "Malürtvej 5", "birgitteKjaer@James.com", "8", 1, CuType1);
        Customer customer2 = new Customer("James Kristian", "Malürtvej 4", "birgitteKjaer2@Kristian.com", "99999999", 2, CuType1);
     
        customers.add(customer1);
        customers.add(customer2);
        
    }
    
    /**
     * Returns an instance of CustomerCon
     * 
     * @return an instance of CustomerCon
     */ 
    public static CustomerCon getInstance(){
        if(instance == null){
            instance = new CustomerCon();
        }
        return instance;
    }
    
    /**
     * Finds a specified Customer Object using that customers phone
     * 
     * @param phone, the phonenumber of the Customer
     * @return the Customer object if found. Else null
     */
    public Customer findCustomer(String phone){
        int i = 0;
        boolean found = false;
        Customer returnCustomer = null;
        while (!found && i<=customers.size()-1){
            if (phone.equalsIgnoreCase(customers.get(i).getPhone())){
                found = true; 
                returnCustomer = customers.get(i); //
            }
               i++;      
        }      
        return returnCustomer;
    }
}
